package com.quanyan.user.web;

import com.quanyan.api.APIResponse;
import com.quanyan.user.model.vo.response.RespUserMedal;
import com.quanyan.user.model.vo.response.RespUserMedalRule;
import com.quanyan.user.service.UserMedalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created by zhang on 16/7/5.
 */
@RestController
@RequestMapping("/api/user/medal")
public class UserMedalController {

    @Autowired
    private UserMedalService userMedalService;

    /**
     * 获取用户徽章列表
     * @param map
     * @param request
     * @return
     */
    @RequestMapping("list")
    public APIResponse<List<RespUserMedal>> list(@RequestBody Map map,HttpServletRequest request){
        int uid = (int) request.getAttribute("uid");
        if(null == map.get("currentUid")){
            return APIResponse.returnFail("请上传必要参数");
        }
        if(null == map.get("type")){
            return APIResponse.returnFail("请上传必要参数");
        }
        if(null == map.get("categoryId")){
            return APIResponse.returnFail("请上传必要参数");
        }
        int currentUid = (int) map.get("currentUid");
        int type = (int) map.get("type");
        int categoryId = (int) map.get("categoryId");
        List<RespUserMedal> respUserMedalList = this.userMedalService.list(currentUid,uid,type,categoryId);
        return APIResponse.returnSuccess(respUserMedalList);
    }

    /**
     * 获得用户勋章详情
     * @param map
     * @param request
     * @return
     */
    @RequestMapping("get")
    public APIResponse<RespUserMedalRule> get(@RequestBody Map map,HttpServletRequest request){
        int uid = (int) request.getAttribute("uid");
        if(null == map.get("medalId")){
            return APIResponse.returnFail("传入必要参数");
        }
        int medalId = (int) map.get("medalId");
        RespUserMedalRule respUserMedalRule = this.userMedalService.get(uid,medalId);
        return APIResponse.returnSuccess(respUserMedalRule);
    }
}
